package com.ssmdemo.pojo;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.ssmdemo.pojo.check.CheckNull;
import com.ssmdemo.pojo.check.CheckType;
import lombok.Data;
import lombok.ToString;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;

@ToString
@Data
public class TUsers implements CheckNull {

    private Long id;
    private String name;
    private String password;
    private String sex;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private java.util.Date birthday;
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone="GMT+8")
    private java.util.Date registTime;

    @Override
    public boolean isEmpty(CheckType type) {
        switch (type) {
            case ADD:
                return !StringUtils.hasText(password) || !StringUtils.hasText(sex);
            case UPDATE:
                return (ObjectUtils.isEmpty(id) || id <= 0) || (
                        !StringUtils.hasText(password)
                                && !StringUtils.hasText(sex)
                                && StringUtils.isEmpty(birthday)
                                && StringUtils.isEmpty(registTime));
        }
        return false;
    }
}
